﻿using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Navigation;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.ScheduleView;

namespace DiagnosticCenter.View
{
    public partial class viewStudentSchedule : Page
    {
        public viewStudentSchedule()
        {
            InitializeComponent();

            var appointments = GenerateStudentAppointment();
            radScheduleView1.AppointmentsSource = appointments;
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

        }

        private static IEnumerable<StudentAppointment> GenerateStudentAppointment()
        {
            var appointments = new List<StudentAppointment>();

            var app = new StudentAppointment
                          {
                              Start = new DateTime(2011, 6, 21, 8, 30, 0),
                              Subject = "Вводный контроль",
                              SubjectName = "АСОУ",
                              Type = "тест",
                              Place = "ауд. 412",
                              Teacher = "Карчевский Виталий Пиусович"
                          };
            app.End = app.Start.AddMinutes(95);
            appointments.Add(app);

            app = new StudentAppointment
                      {
                          Start = new DateTime(2011, 6, 25, 8, 30, 0),
                          Subject = "Модуль 2",
                          SubjectName = "Эргономика",
                          Type = "экзамен",
                          Place = "ауд. 412",
                          Teacher = "Карчевский Виталий Пиусович"
                      };
            app.End = app.Start.AddMinutes(95);
            appointments.Add(app);

            return appointments;
        }

        //radScheduleView ReadOnly
        private void radScheduleView1_ShowDialog(object sender, ShowDialogEventArgs e)
        {
            e.Cancel = true;
        }
        private void radScheduleView1_AppointmentCreating(object sender, AppointmentCreatingEventArgs e)
        {
            e.Cancel = true;
        }
        private void radScheduleView1_AppointmentDeleting(object sender, AppointmentDeletingEventArgs e)
        {
            e.Cancel = true;
        }
        private void radScheduleView1_AppointmentEditing(object sender, AppointmentEditingEventArgs e)
        {
            e.Cancel = true;
        }
    }

    public class ViewModel : ViewModelBase
    {

    }

    public class StudentAppointment : AppointmentBase
    {
        private string subjname;
        public string SubjectName
        {
            get
            {
                return subjname;
            }
            set
            {
                if (subjname != value)
                {
                    subjname = value;
                    OnPropertyChanged("SubjectName");
                }
            }
        }

        private string type;
        public string Type
        {
            get
            {
                return type;
            }
            set
            {
                if (type != value)
                {
                    type = value;
                    OnPropertyChanged("Type");
                }
            }
        }

        private string place;
        public string Place
        {
            get
            {
                return place;
            }
            set
            {
                if (place != value)
                {
                    place = value;
                    OnPropertyChanged("Place");
                }
            }
        }

        private string teacher;
        public string Teacher
        {
            get
            {
                return teacher;
            }
            set
            {
                if (teacher != value)
                {
                    teacher = value;
                    OnPropertyChanged("Teacher");
                }
            }
        }


        public override IAppointment Copy()
        {
            IAppointment appointment = new StudentAppointment();
            appointment.CopyFrom(this);
            return appointment;
        }

        public override void CopyFrom(IAppointment other)
        {
            base.CopyFrom(other);
            var appointment = other as StudentAppointment;

            if (appointment != null)
            {
                Teacher = appointment.Teacher;
                Place = appointment.Place;
            }
        }
    }

    //radScheduleView ReadOnly
    class ReadOnlyDragAndDropBehavior : DefaultDragDropBehavior
    {
        public override bool CanDrop(DragDropState state)
        {
            return false;
        }

        public override bool CanResize(DragDropState state)
        {
            return false;
        }
    }
}

//TODO: ADD: По нажатию на сеанс тестирования, который был пройден, выводить окно результата тестов